// -*- c++ -*-
/**************************************************************/
/*  This file is licensed from, and is a trade secret of:     */
/*                                                            */
/*    Mercury Computer Systems, Incorporated                  */
/*    199 Riverneck Road                                      */
/*    Chelmsford, Massachusetts 01824-2820                    */
/*    United States of America                                */
/*    Telephone + 1 978 256-1300                              */
/*                                                            */
/*  Refer to your Software License Agreement for provisions   */
/*  on use, duplication, or disclosure.                       */
/*  US. Government users and prime contractors are also       */
/*  governed by the following Data Rights Notice:             */
/*  Use, duplication or disclosure by the US. Government is   */
/*  subject to the provisions set forth in FAR 52.227-14 for  */
/*  restricted rights or other agency data rights provisions  */
/*  on commercial software and documentation, as applicable.  */
/*                                                            */
/*  This file: (a) was developed at private expense, and no   */
/*  part was developed with government funds, (b) is a        */
/*  trade secret of Mercury Computer Systems, Inc. for the    */
/*  purposes of the Freedom of Information Act, (c) is        */
/*  "commercial computer software" subject to limited         */
/*  utilization as provided in the above noted Software       */
/*  License Agreement and (d) is in all respects data         */
/*  belonging exclusively to Mercury Computer Systems, Inc..  */
/*                                                            */
/**************************************************************/

/******************************************************************/
/* Copyright (c) 1999-2003, Mercury Computer Systems, Inc.,       */
/* Chelmsford MA.,and all third party embedded software sources.  */
/* All rights reserved under the Copyright laws of US. and        */
/* international treaties.                                        */
/*                                                                */
/* Patent Pending                                                 */
/******************************************************************/


//$COPYRIGHT_END


#ifndef SCEOSASSERT_H__
#define SCEOSASSERT_H__

/*
 * Abstract:
 *
 *     The sceAssert() macro.
 */

#include <iostream>

namespace SCE {
  namespace OS {

    /*
     * Sets the output for "assertion failed" messages. (Defaults to
     * std::cerr).
     *
     * [in] out: The stream to print "assertion failed" messages to.
     */

    void setAssertOutput (std::ostream & out)
      throw ();

    /*
     * These operations are called by the sceAssert() macro below.
     */

    bool testAssertion (bool)
      throw ();

    bool assertionFailed (const char *, const char *, unsigned int)
      throw ();

  }
}

/*
 * "Test" an assertion condition. There isn't really anything to test.
 * This is just to avoid warnings like "statement has no effect" when
 * testing for something like sceAssert (sizeof(int) == 4).
 */

inline
bool
SCE::OS::testAssertion (bool cond)
  throw ()
{
  return !!cond;
}

/*
 * Tests a "sanity check" condition. When the NDEBUG preprocessor
 * symbol is not defined, the condition is evaluated. If true, the
 * program continues. If false, a message and stack trace are
 * printed to the output stream set using the setAssertOutput()
 * operation above. In this case, the function does not return,
 * but first breaks into the debugger using debugBreak(), and then
 * aborts the program. If the NDEBUG preprocessor symbol is defined,
 * then the condition is not evaluated, and the program continues
 * regardless of its value.
 */

#if defined (sceAssert)
#undef sceAssert
#endif

#if defined (NDEBUG)
#define sceAssert(cond) ((void)0)
#else
#define sceAssert(cond) ((::SCE::OS::testAssertion ((cond) ? true : false)) || ::SCE::OS::assertionFailed (#cond, __FILE__, __LINE__))
#endif

#endif
